package com.cote.douhahou.pretloan.msg;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.PickVisualMediaRequest;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.cote.douhahou.pretloan.beans.PersAkomapalendonalInfo;
import com.cote.douhahou.pretloan.beans.ProceAkomapalendssInfoStep;
import com.cote.douhahou.pretloan.beans.ProcesAkomapalendsInfoData;
import com.cote.douhahou.pretloan.beans.ProcessInAkomapalendfo;
import com.cote.douhahou.pretloan.msg.widget.BaseProcAkomapalendessWidgetManager;
import com.cote.douhahou.pretloan.msg.widget.BindAccoAkomapalenduntViewManager;
import com.cote.douhahou.pretloan.msg.widget.DateSAkomapalendelectViewManager;
import com.cote.douhahou.pretloan.msg.widget.FaceAkomapalendViewManager;
import com.cote.douhahou.pretloan.msg.widget.GeAkomapalendnderSelectViewManager;
import com.cote.douhahou.pretloan.msg.widget.InputAkomapalendViewManager;
import com.cote.douhahou.pretloan.msg.widget.OcrVieAkomapalendwManager;
import com.cote.douhahou.pretloan.msg.widget.SeleAkomapalendctViewMana;
import com.cote.douhahou.pretloan.network.HttpHelper;
import com.cote.douhahou.pretloan.service.CusServiceAkomapalendDialog;
import com.cote.douhahou.pretloan.utils.AkomapaLendConfigs;
import com.cote.douhahou.pretloan.utils.AkomapaLendUtil;
import com.cote.douhahou.pretloan.utils.image_akomapalend.ImageConvert;
import com.cote.douhahou.pretloan.R;
import com.cote.douhahou.pretloan.apply.LoanApplyActivity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

import pub.devrel.easypermissions.AppSettingsDialog;
import pub.devrel.easypermissions.EasyPermissions;

public class MessageActivity extends AppCompatActivity implements EasyPermissions.RationaleCallbacks,EasyPermissions.PermissionCallbacks{

    private LinearLayout parentGroupLayout;
    private View continueBtn;
    private TextView titleTv;

    private ProceAkomapalendssInfoStep step_akomapalend;

    private final ArrayList<BaseProcAkomapalendessWidgetManager> processWidgetManagers_akomapalend = new ArrayList<>();

    private BindAccoAkomapalenduntViewManager bindAccountViewManager_akomapalend;//法语区绑卡组件
    private OcrVieAkomapalendwManager ocrViewManager_akomapalend;//Ocr组件
    private FaceAkomapalendViewManager faceViewManager_akomapalend;//Face组件

    private String path_akomapalend;

    private Runnable nextBtnRunnable_akomapalend;

    private String currentStepName = "";

    private final String[] userNames = new String[]{"","",""};

    private static String page_akomapalend = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info_process);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);

        currentStepName = ProcessInAkomapalendfo.instance().getStepName_akomapalend(0);

        if (!TextUtils.isEmpty(currentStepName)) page_akomapalend = currentStepName.toUpperCase();
        else page_akomapalend = getClass().getSimpleName().toUpperCase();

        findViewById(R.id.apa2_ib_back).setOnClickListener(v -> onBackPressed());
        findViewById(R.id.apa2_ib_customer_service).setOnClickListener(v -> new CusServiceAkomapalendDialog(this).show());

        parentGroupLayout = findViewById(R.id.apa2_layout_group);
        continueBtn = findViewById(R.id.apa2_btn_continue);
        titleTv = findViewById(R.id.apa2_tv_title);

        step_akomapalend = ProcessInAkomapalendfo.instance().getStep_akomapalend(0);
        path_akomapalend = step_akomapalend == null ? "": step_akomapalend.getApiUrl_akomapalend();

        //next
        continueBtn.setOnClickListener(v -> {
            HttpHelper.inst().submitEvent(page_akomapalend,"SAVE_CLICK","");
            if (step_akomapalend == null||TextUtils.isEmpty(path_akomapalend)) {
                onBackPressed();
                return;
            }
            if (nextBtnRunnable_akomapalend !=null) nextBtnRunnable_akomapalend.run();
        });

        initProcessStep();

    }

    //流程步骤框架
    private void initProcessStep(){

        //Ocr和人脸流程直接添加
        if (currentStepName.equalsIgnoreCase(AkomapaLendConfigs.StepOcr)){
            titleTv.setText(getString(R.string.process_title_ocr));
            initOcrProcess_akomapalend(parentGroupLayout);
            return;
        }else if (currentStepName.equalsIgnoreCase(AkomapaLendConfigs.StepFace)){
            titleTv.setText(getString(R.string.process_title_face));
            initFaceProcess_akomapalend(parentGroupLayout);
            return;
        }

        ArrayList<String> allSteps = ProcessInAkomapalendfo.instance().getAllSteps_akomapalend();
        ArrayList<String> steps = ProcessInAkomapalendfo.instance().getSteps_akomapalend();

        for (int i=0;i<allSteps.size();i++){

            String stepName = allSteps.get(i);

            if (!steps.contains(stepName)){//已完成流程
                //添加已完成流程展示
                View item = View.inflate(this,R.layout.view_process_state_2,null);
                TextView stepNameTv = item.findViewById(R.id.vpifa_tv_step_name);
                stepNameTv.setText(ProcessInAkomapalendfo.instance().getStepTitle_akomapalend(i));
                parentGroupLayout.addView(item);
            }else if (stepName.equalsIgnoreCase(currentStepName)){//当前流程
                //添加当前流程展示
                View item = View.inflate(this,R.layout.view_process_3,null);
                TextView stepNameTv = item.findViewById(R.id.vpica_tv_step_name);
                stepNameTv.setText(ProcessInAkomapalendfo.instance().getStepTitle_akomapalend(i));
                initProcessItems_akomapalend(item.findViewById(R.id.vpica_layout_group));
                parentGroupLayout.addView(item);
            }else {//后续流程
                //添加后续流程展示
                View item = View.inflate(this,R.layout.view_process_state,null);
                TextView stepNameTv = item.findViewById(R.id.vpia_tv_step_name);
                stepNameTv.setText(ProcessInAkomapalendfo.instance().getStepTitle_akomapalend(i));
                parentGroupLayout.addView(item);
            }

        }

    }

//-----------------------Old-------------------------------
    /**
     * 流程
     */
    @SuppressLint("SetTextI18n")
    private void initProcessItems_akomapalend(LinearLayout groupLayout){
        if (step_akomapalend == null) {
            onBackPressed();
            return;
        }

        //根据流程类型分别处理
        switch (currentStepName){
            case AkomapaLendConfigs.StepContact://联系人流程
                initContactProcess_akomapalend(groupLayout);
                break;
            case AkomapaLendConfigs.StepAccount://绑卡流程
                if (AkomapaLendUtil.isTsBindAccount()){//法语区绑卡流程
                    initBindAccountProcess_Fr_akomapalend(groupLayout);
                    HttpHelper.inst().fAccountList(this,this::onFetchFrAccountListResponse_akomapalend);
                    break;
                }
            default://普通流程
                initNormalProcess_akomapalend(groupLayout);
        }

    }

    /**
     * 普通流程
     */
    private void initNormalProcess_akomapalend(LinearLayout groupLayout){

        View group2View = View.inflate(this,R.layout.view_item_group,null);
        LinearLayout group2Layout = group2View.findViewById(R.id.vibg_layout_group);

        for (int i = 0; i< step_akomapalend.getDataListSize_akomapalend(); i++){
            ProcesAkomapalendsInfoData data = step_akomapalend.getProcessData_akomapalend(i);
            if (data==null) continue;
            addInputView_akomapalend(data,null,group2Layout);
        }

        //数据上报处理
        nextBtnRunnable_akomapalend = () -> {

            for (BaseProcAkomapalendessWidgetManager processWidgetManager: processWidgetManagers_akomapalend){
                if (!processWidgetManager.checkI_akomapalendnput()){
                    Toast.makeText(this,getString(R.string.tips_input_empty_akomapalend),Toast.LENGTH_SHORT).show();
                    return;
                }
            }

            TreeMap<String,String> dataMap = new TreeMap<>();

            for (BaseProcAkomapalendessWidgetManager baseInfoInputViewManager: processWidgetManagers_akomapalend){

                ProcesAkomapalendsInfoData data = baseInfoInputViewManager.getDa_akomapalendta();
                if (data==null) continue;

                //地址联动模块
//                if (data.getAction_akomapalend().equalsIgnoreCase(AkomapaLendConfigs.Data_Action_AddressPick_akomapalend)){
//                    //坦桑尼亚
//                    if (AkomapaLendUtil.isTanzan_akomapalend()){
//                        if (!(baseInfoInputViewManager instanceof AddressPickViewManager_Tanzan_akomapalend)) continue;
//                        AddressPickViewManager_Tanzan_akomapalend addressPickTanzanManager = (AddressPickViewManager_Tanzan_akomapalend) baseInfoInputViewManager;
//                        dataMap.put(data.getParamName_akomapalend(),addressPickTanzanManager.getState_akomapalend().trim());
//                        dataMap.put(data.getParamNameCity_akomapalend(),addressPickTanzanManager.getCity_akomapalend().trim());
//                    }
//                }
                //常规模块
                else dataMap.put(data.getParamName_akomapalend(),baseInfoInputViewManager.getInp_akomapalendut().trim());

            }

            HttpHelper.inst().processSubmit(this, path_akomapalend,dataMap,() -> {

                for (String k:dataMap.keySet()){
                    String v = dataMap.get(k);
                    extractPersonalInfo(k,v);
                }

                onSubmitInfoResponse_akomapalend();
            });

        };

        groupLayout.addView(group2View);
    }

    /**
     * 联系人流程
     */
    @SuppressLint("InflateParams")
    private void initContactProcess_akomapalend(LinearLayout groupLayout){

        View group2View = View.inflate(this,R.layout.view_item_group,null);
        LinearLayout group2Layout = group2View.findViewById(R.id.vibg_layout_group);

        for (int i = 0; i< step_akomapalend.getExtDataListSize_akomapalend(); i++){
            ProcesAkomapalendsInfoData data = step_akomapalend.getExtProcessData_akomapalend(i);
            if (data==null) continue;
            addInputView_akomapalend(data,null,group2Layout);
        }

        if (step_akomapalend.getItemCount_akomapalend()<=0) return;

        //添加一组联系人输入控件
        if (step_akomapalend.getExtDataListSize_akomapalend()>0) groupLayout.addView(group2View);
        //重新一组新的联系人输入控件
        group2View = View.inflate(this,R.layout.view_item_group,null);
        group2Layout = group2View.findViewById(R.id.vibg_layout_group);

        int count = 0;

        while (count< step_akomapalend.getItemCount_akomapalend()){//联系人数量
            for (int i = 0; i< step_akomapalend.getDataListSize_akomapalend(); i++){
                ProcesAkomapalendsInfoData data = step_akomapalend.getProcessData_akomapalend(i);
                if (data==null) continue;
                addInputView_akomapalend(data, step_akomapalend.getRelationShips_akomapalend(count),group2Layout);
            }

            //添加一组联系人输入控件
            groupLayout.addView(group2View);

            if (++count < step_akomapalend.getItemCount_akomapalend()){
                //重新一组新的联系人输入控件
                group2View = View.inflate(this,R.layout.view_item_group,null);
                group2Layout = group2View.findViewById(R.id.vibg_layout_group);
            }else break;
        }

        //数据上报处理
        nextBtnRunnable_akomapalend = () -> {

            TreeMap<String,String> dataMap = new TreeMap<>();

            ArrayList<String> relashipList = new ArrayList<>();
            ArrayList<String> nameList = new ArrayList<>();
            ArrayList<String> phoneList = new ArrayList<>();

            for (BaseProcAkomapalendessWidgetManager baseInfoInputViewManager: processWidgetManagers_akomapalend){

                ProcesAkomapalendsInfoData data = baseInfoInputViewManager.getDa_akomapalendta();
                if (data==null) continue;
                switch (data.getAction_akomapalend()){

                    case AkomapaLendConfigs.DataContactRelation:
                        relashipList.add(((SeleAkomapalendctViewMana)baseInfoInputViewManager).getTe_akomapalendxtInput());
                        break;

                    case AkomapaLendConfigs.DataContactName:
                        nameList.add(baseInfoInputViewManager.getInp_akomapalendut());
                        break;

                    case AkomapaLendConfigs.DataContactPhone:
                        phoneList.add(baseInfoInputViewManager.getInp_akomapalendut());
                        break;

                    default: dataMap.put(data.getParamName_akomapalend(),baseInfoInputViewManager.getInp_akomapalendut().trim());
                }

            }

            //添加联系人信息
            if (!TextUtils.isEmpty(step_akomapalend.getContactParamName_akomapalend())){
                JSONArray jsonArray = new JSONArray();
                for (int i=0;i<relashipList.size();i++){
                    JSONObject jsonObject = new JSONObject();
                    try {
                        jsonObject.put("relation",relashipList.get(i).trim());
                        if (i<nameList.size()) jsonObject.put("fullName",nameList.get(i).trim());
                        if (i<phoneList.size()) jsonObject.put("mobile",phoneList.get(i).trim());
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    jsonArray.put(jsonObject);
                }
                dataMap.put(step_akomapalend.getContactParamName_akomapalend(),jsonArray.toString());
            }

            HttpHelper.inst().processSubmit(this, path_akomapalend,dataMap,this::onSubmitInfoResponse_akomapalend);

        };

    }

    /**
     * 法语区绑卡流程
     */
    private void initBindAccountProcess_Fr_akomapalend(LinearLayout groupLayout){

        View group2View = View.inflate(this,R.layout.view_item_group,null);
        LinearLayout group2Layout = group2View.findViewById(R.id.vibg_layout_group);

        @SuppressLint("InflateParams") View bindAccountView = LayoutInflater.from(this).inflate(R.layout.item_process_bind_account,null);
        bindAccountViewManager_akomapalend = new BindAccoAkomapalenduntViewManager(bindAccountView,null, page_akomapalend);
        group2Layout.addView(bindAccountView);

        continueBtn.setBackgroundResource(R.drawable.gray_round_corner_4);

        AccAkomapalendountList.instance().setParseRunnable_akomapalend(() -> {
            if (AccAkomapalendountList.instance().getBankAccountList_akomapalend().isEmpty())
                continueBtn.setBackgroundResource(R.drawable.gray_round_corner_4);
            else
                continueBtn.setBackgroundResource(R.drawable.back_3_color_gradient);
        });

        nextBtnRunnable_akomapalend = () -> {

            if (bindAccountView == null) {
                onBackPressed();
                return;
            }

            if (AccAkomapalendountList.instance().getBankAccountList_akomapalend().isEmpty()){//无绑卡提示
                Toast.makeText(this,"Veuillez ajouter au moins un compte de réception de prêt valide.",Toast.LENGTH_SHORT).show();
                return;
            }

            if (AccAkomapalendountList.instance().getBankAccountList_akomapalend().size()<2){
                new BindAccAkomapalendountTipDialog(this,() -> {
                    //提交绑卡
                    new SubmitAccountAkomapalendDialog(this, this::onSubmitInfoResponse_akomapalend
                            , page_akomapalend).show();
                }).show();
                return;
            }

            new SubmitAccountAkomapalendDialog(this,() ->
                //提交绑卡
                HttpHelper.inst().process(this,this::onProcessInfoResponse_akomapalend)
            , page_akomapalend).show();

        };


        groupLayout.addView(group2View);
    }

    /**
     * 人脸流程
     */
    private void initFaceProcess_akomapalend(LinearLayout groupLayout){

        @SuppressLint("InflateParams") View faceView = LayoutInflater.from(this).inflate(R.layout.item_face,null);
        faceViewManager_akomapalend = new FaceAkomapalendViewManager(
                faceView,null, page_akomapalend,
                this::onProcessInfoResponse_akomapalend,
                () -> {if (faceViewManager_akomapalend !=null) faceViewManager_akomapalend.onPhotoUplo_akomapalendadRespo_akomapalendnse();}
        );
        groupLayout.addView(faceView);

        nextBtnRunnable_akomapalend = () -> {
            if (faceView==null || faceViewManager_akomapalend ==null) {
                onBackPressed();
                return;
            }
            faceViewManager_akomapalend.nextCl_akomapalendick(path_akomapalend);
        };

    }

    /**
     * Ocr流程
     */
    private void initOcrProcess_akomapalend(LinearLayout groupLayout){

        @SuppressLint("InflateParams") View ocrView = LayoutInflater.from(this).inflate(R.layout.item_certificate,null);
        ocrViewManager_akomapalend = new OcrVieAkomapalendwManager(
                ocrView,null, page_akomapalend,
                this::onProcessInfoResponse_akomapalend,
                () -> {if (ocrViewManager_akomapalend !=null) ocrViewManager_akomapalend.onPhot_akomapalendoUploadRe_akomapalendsponse();}
        );
        groupLayout.addView(ocrView);

        ActivityResultLauncher<PickVisualMediaRequest> pickMedia_akomapalend = registerForActivityResult(new ActivityResultContracts.PickVisualMedia(), uri -> {
            if (uri != null && ocrViewManager_akomapalend != null) {
                ocrViewManager_akomapalend.pho_akomapalendtoUri = uri;
                ocrViewManager_akomapalend.imgPa_akomapalendth = ImageConvert.bitmapFilePathFromURI(this, ocrViewManager_akomapalend.pho_akomapalendtoUri);
                ocrViewManager_akomapalend.onPh_akomapalendot_akomapalendoGet();
            }
        });

        ocrViewManager_akomapalend.set_akomapalendPick_akomapalendMe(pickMedia_akomapalend);

        nextBtnRunnable_akomapalend = () -> {
            if (ocrView == null || ocrViewManager_akomapalend ==null) {
                onBackPressed();
                return;
            }
            ocrViewManager_akomapalend.nextC_akomapalendlick(path_akomapalend);
        };

    }

    /**
     * 添加信息输入控件
     * @param data 控件参数
     * @param relationships 联系人关系选项，可为空
     * @param groupLayout 控件容器
     */
    @SuppressLint("InflateParams")
    private void addInputView_akomapalend(ProcesAkomapalendsInfoData data, ArrayList<String> relationships, LinearLayout groupLayout){

        View inputView = null;

        switch (data.getAction_akomapalend()){

            case AkomapaLendConfigs.DataSelect:
                inputView = LayoutInflater.from(this).inflate(R.layout.item_choose,null);
                SeleAkomapalendctViewMana selectViewManager = new SeleAkomapalendctViewMana(inputView,data, page_akomapalend);
                processWidgetManagers_akomapalend.add(selectViewManager);
                break;

            case AkomapaLendConfigs.DataPick:
                inputView = LayoutInflater.from(this).inflate(R.layout.item_process_date,null);
                DateSAkomapalendelectViewManager datePickWidgetsManager = new DateSAkomapalendelectViewManager(inputView,data, page_akomapalend);
                processWidgetManagers_akomapalend.add(datePickWidgetsManager);
                break;

            case AkomapaLendConfigs.DataContactRelation://联系人-关系
                if (relationships!=null) data.setRelationships_akomapalend(relationships);
                inputView = LayoutInflater.from(this).inflate(R.layout.item_choose,null);
                SeleAkomapalendctViewMana contactSelectViewManager = new SeleAkomapalendctViewMana(inputView,data, page_akomapalend);
                processWidgetManagers_akomapalend.add(contactSelectViewManager);
                break;

            case AkomapaLendConfigs.DataGender:
                inputView = LayoutInflater.from(this).inflate(R.layout.item_gender,null);
                GeAkomapalendnderSelectViewManager genderSelectViewManager = new GeAkomapalendnderSelectViewManager(inputView,data, page_akomapalend);
                processWidgetManagers_akomapalend.add(genderSelectViewManager);
                break;

            case AkomapaLendConfigs.DataInput:
            case AkomapaLendConfigs.DataContactName://联系人-名字
            case AkomapaLendConfigs.DataContactPhone://联系人-电话
            default:
                inputView = LayoutInflater.from(this).inflate(R.layout.item_process_input,null);
                InputAkomapalendViewManager inputWidgetsManager = new InputAkomapalendViewManager(inputView,data, page_akomapalend);
                processWidgetManagers_akomapalend.add(inputWidgetsManager);
                break;
        }

        if (inputView!=null) groupLayout.addView(inputView);
    }



//-------------------------------------------Permission处理-----------------------------------------------------------
    @Override
    public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
        if (requestCode == AkomapaLendConfigs.PermissionCCamera){
            if (faceViewManager_akomapalend != null) faceViewManager_akomapalend.onCameraPer_akomapalendmission_akomapalendAgree();
            else if (ocrViewManager_akomapalend !=null) ocrViewManager_akomapalend.onCam_akomapalenderaPermissio_akomapalendnAgree();
        }
    }

    @Override
    public void onRationaleDenied(int requestCode) {}

    @Override
    public void onRationaleAccepted(int requestCode) {
        if (requestCode == AkomapaLendConfigs.PermissionCCamera)
            EasyPermissions.requestPermissions(this,
                    getString(R.string.request_permission_camera),
                    AkomapaLendConfigs.PermissionCCamera,
                    Manifest.permission.CAMERA);
    }

    @Override
    public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
        if (requestCode == AkomapaLendConfigs.PermissionCCamera) {
            if (EasyPermissions.somePermissionPermanentlyDenied(this, perms))
                new AppSettingsDialog.Builder(this).build().show();
        }
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (ocrViewManager_akomapalend !=null && requestCode== OcrVieAkomapalendwManager.Flag_StartCam_akomapalendera){
            ocrViewManager_akomapalend.onPh_akomapalendot_akomapalendoGet();
        }
    }

    //-------------------------------------------响应-----------------------------------------------------------

    //信息上报成功响应
    public void onSubmitInfoResponse_akomapalend(){
        HttpHelper.inst().process(this,this::onProcessInfoResponse_akomapalend);
    }

    public void onFetchFrAccountListResponse_akomapalend(){
        if (bindAccountViewManager_akomapalend !=null) bindAccountViewManager_akomapalend.refreshAcc_akomapalendountList();
    }

    public void onProcessInfoResponse_akomapalend(){
        //无流程:跳转到申请页
        if (ProcessInAkomapalendfo.instance().getSteps_akomapalend().isEmpty())
            startActivity(new Intent(this, LoanApplyActivity.class));
            //有流程:跳转到流程页
        else startActivity(new Intent(this, MessageActivity.class));

        finish();
    }


    //----------------------------------------提取基本信息中的全名和性别----------------------------
    private void extractPersonalInfo(String key,String value){
        if (!currentStepName.equalsIgnoreCase(AkomapaLendConfigs.StepPersonal)) return;
        switch (key){
            case "gender":
                if (value.equalsIgnoreCase("MALE")) PersAkomapalendonalInfo.instance().setUserGender(getString(R.string.personal_gender_male));
                else if (value.equalsIgnoreCase("FEMALE")) PersAkomapalendonalInfo.instance().setUserGender(getString(R.string.personal_gender_female));
                else PersAkomapalendonalInfo.instance().setUserGender(getString(R.string.personal_gender_unknown));
                PersAkomapalendonalInfo.instance().uploadUserInfo(null,null);
                break;
            case "firstName":
                userNames[0] = value.trim();
                break;
            case "middleName":
                userNames[1] = value.trim();
                break;
            case "lastName":
                userNames[2] = value.trim();
                break;

        }

        if (!TextUtils.isEmpty(userNames[0]) && !TextUtils.isEmpty(userNames[2])){
            PersAkomapalendonalInfo.instance().setFullName(
                    userNames[0]+" "+(TextUtils.isEmpty(userNames[1]) ? "":userNames[1]+" ")+userNames[2]
            );
            PersAkomapalendonalInfo.instance().uploadUserInfo(null,null);
        }

    }



    @Override
    protected void onResume() {
        super.onResume();
        HttpHelper.inst().submitEvent(page_akomapalend,"START","");
    }

    @Override
    protected void onPause() {
        super.onPause();
        HttpHelper.inst().submitEvent(page_akomapalend,"END","");
    }

}